package com.ruoyi.boat.controller;


import com.ruoyi.boat.domain.Boat;
import com.ruoyi.boat.domain.Status;

import com.ruoyi.boat.service.IBoatService;
import com.ruoyi.boat.service.IStatusService;

import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@Slf4j
@RequestMapping("/map")
public class MapController {

    @Autowired
    IBoatService boatService;
    
    @Autowired
    IStatusService statusService;

    @Autowired
    private ISysConfigService configService;

    @GetMapping("")
    public String index() {
        return "redirect:/";
    }

    /**
     * 气象站 0
     * AIS 1
     * 大气波导 2
     * 测风雷达 3
     * 波浪仪 4
     * ADCP 5
     * CTD 6
     * 水质传感器 7
     * 通信机 8
     * @param mmap
     * @param boatId
     * @param deviceType
     * @return
     */
    @GetMapping("/device")
    public String device(ModelMap mmap, @RequestParam Long boatId, @RequestParam Integer deviceType) {
        mmap.put("boat", boatService.selectBoatById(boatId));
        mmap.put("deviceType", deviceType);
        String pageName = "";
        switch (deviceType) {
            case 0:
                pageName = "map/devices/meteor";
                break;
            case 1:
                pageName = "map/devices/AIS";
                mmap.put("mapHost",configService.selectConfigByKey("sys.map.host"));
                break;
            case 2:
                pageName = "map/devices/Atmos";
                break;
            case 3:
                pageName = "map/devices/radar";
                break;
            case 4:
                pageName = "map/devices/wave";
                break;
            case 5:
                pageName = "map/devices/ADCP";
                break;
            case 6:
                pageName = "map/devices/CTD";
                break;
            case 7:
                pageName = "map/devices/water";
                break;
            case 8:
                pageName = "map/devices/communicator";
                break;
            default:
                pageName = "map/device";
        }
        return pageName;
    }

    @GetMapping("/route")
    public String route(ModelMap mmap, @RequestParam Long boatId) {
        Boat boat = boatService.selectBoatById(boatId);
        Status status = statusService.selectLatestStatusByCode(boat.getCode());
        mmap.put("boat", boat);
        mmap.put("status", status);
        mmap.put("mapHost", configService.selectConfigByKey("sys.map.host"));
        return "map/route";
    }

}
